<template>
  <div>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <template #toolbar>
        <a-button type="primary" @click="handleAdd" v-auth="'ACTION_addAppUser'"> 新增</a-button>
        <a-button type="primary" @click="handleAdd1" v-auth="'ACTION_addVipRecord'"> 补增</a-button>
      </template>
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>
    <BusViprecordDrawer @register="registerDrawer" @success="handleSuccess" />
    <BusViprecordDrawer1 @register="registerDrawer1" @success="handleSuccess" />
    <BusViprecordDetailModal @register="registerViprecordDetailModal" />
    <BusViprecordCheckModal @register="registerViprecordCheckModal" @success="handleSuccess" />
  </div>
</template>
<script lang="ts" setup name="vipRecord">
import { ActionItem, BasicTable, TableAction } from '@apps/antd-admin/src/components/Table';
import { useDrawer } from '@apps/antd-admin/src/components/drawer';
import { useBaseTable } from '@apps/antd-admin/src/hooks';
import { useModal } from '@apps/antd-admin/src/components/modal';
import BusViprecordDrawer from './components/BusViprecordDrawer.vue';
import BusViprecordDrawer1 from './components/BusViprecordDrawer1.vue';
import BusViprecordDetailModal from './components/BusViprecordDetailModal.vue';
import BusViprecordCheckModal from './components/BusViprecordCheckModal.vue';
import { Api } from './data/viprecord.api';
import { columns, searchFormSchema } from './data/viprecord.data';

const [registerDrawer, { openDrawer }] = useDrawer();
const [registerDrawer1, { openDrawer: openDrawer1 }] = useDrawer();
//初始化Table
const { prefixCls, tableContext, handleDelete, handleSuccess } = useBaseTable({
  designScope: 'viprecord-template',
  tableProps: {
    title: '新增会员记录',
    columns: columns,
    //主键字段
    rowKey: 'vipRecordId',
    //分页列表接口
    listUrl: Api.page,
    //删除接口
    delUrl: Api.remove,
    //是否显示索引列
    showIndexColumn: true,
    //查询form配置
    formConfig: {
      schemas: searchFormSchema,
    },
    //操作列配置
    actionColumn: {
      width: 120,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: 'right',
    },
    clickToRowSelect: true,
    rowSelection: {
      type: 'radio',
    },
  },
});
const [registerTable, { reload }, { rowSelection, hasSelectedRows }] = tableContext;

const [registerViprecordDetailModal, { openModal: openViprecordDetailModal }] = useModal();
const [registerViprecordCheckModal, { openModal: openViprecordCheckModal }] = useModal();

/**
 * 行内操作栏
 */
function getTableAction(record): ActionItem[] {
  return [
    {
      label: '详情',
      onClick: handleDetail.bind(null, record),
    },
    {
      label: '审核',
      onClick: handleCheck.bind(null, record),
      ifShow: _action => {
        return record.isCheck == 1;
      },
    },
  ];
}

/**
 * 新增事件
 */
function handleAdd() {
  openDrawer(true, {
    isUpdate: false,
  });
}

/**
 * 补增事件
 */
function handleAdd1() {
  openDrawer1(true, {
    isUpdate: false,
  });
}

/**
 * 编辑事件
 * @param record
 */
function handleEdit(record) {
  openDrawer(true, {
    record,
    isUpdate: true,
  });
}

/**
 * 查看详情
 * @param record
 */
function handleDetail(record) {
  openViprecordDetailModal(true, {
    record,
    isUpdate: false,
  });
}

/**
 * 审核事件
 * @param record
 */
function handleCheck(record) {
  openViprecordCheckModal(true, {
    record,
    isUpdate: false,
  });
}
</script>
